home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / ANSI.C next >
Text File  |  1991-09-23  |  2KB  |  116 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)ansi.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STDDEF
  11. #include <stddef.h>
  12. #endif
  13. #include <stdio.h>
  14.  
  15. /* function declarations */
  16. #ifdef AC_PROTO
  17. int link(const char *path1, const char *path2);
  18. int unlink(const char *path);
  19. #else
  20. int link();
  21. int unlink();
  22. #endif
  23.  
  24. /* global data declarations */
  25. extern char *sys_errlist[];
  26. extern int sys_nerr;
  27.  
  28. /*man---------------------------------------------------------------------------
  29. NAME
  30.     ansi - ANSI functions required by cbase
  31.  
  32. DESCRIPTION
  33.     This file contains ANSI functions required by cbase which may not
  34.     be available with older compilers.  It is likely to require
  35.     editing.
  36.  
  37. ------------------------------------------------------------------------------*/
  38. #ifndef AC_STRING
  39. /* memmove:  memory move */
  40. #ifdef AC_PROTO
  41. void *memmove(void *t, const void *s, size_t n)
  42. #else
  43. void *memmove(t, s, n)
  44. void *t;
  45. const void *s;
  46. size_t n;
  47. #endif
  48. {
  49.     int i = 0;
  50.  
  51.     if (t < s) {
  52.         for (i = 0; i < n; ++i) {
  53.             *((char *)t + i) = *((char *)s + i);
  54.         }
  55.     } else {
  56.         for (i = n - 1; i >= 0; --i) {
  57.             *((char *)t + i) = *((char *)s + i);
  58.         }
  59.     }
  60.  
  61.     return t;
  62. }
  63. #endif
  64.  
  65. #ifdef AC_PROTO
  66. void perror(const char *s)
  67. #else
  68. void perror(s)
  69. const char *s;
  70. #endif
  71. {
  72.     if (s != NULL) {
  73.         fputs(s, stderr);
  74.         fputs(": ", stderr);
  75.     }
  76.     if (errno >= 0 && errno < sys_nerr) {
  77.         fprintf(stderr, "%s\n", sys_errlist[errno]);
  78.     } else {
  79.         fprintf(stderr, "Error number %d\n", errno);
  80.     }
  81.  
  82.     return;
  83. }
  84.  
  85. #ifdef AC_PROTO
  86. int remove(const char *filename)
  87. #else
  88. int remove(filename)
  89. const char *filename;
  90. #endif
  91. {
  92.     if (unlink(filename) == -1) {
  93.         return -1;
  94.     }
  95.  
  96.     return 0;
  97. }
  98.  
  99. #ifdef AC_PROTO
  100. int rename(const char *file1, const char *file2)
  101. #else
  102. int rename(file1, file2)
  103. const char *file1;
  104. const char *file2;
  105. #endif
  106. {
  107.     if (link(file1, file2) == -1) {
  108.         return -1;
  109.     }
  110.     if (unlink(file1) == -1) {
  111.         return -1;
  112.     }
  113.  
  114.     return 0;
  115. }
  116.